import asyncio
from websocket_communication import handler, connect_to_remote, forward_from_remote_to_clients

async def main():
    # 启动中转服务器
    start_server = websockets.serve(handler, "0.0.0.0", 18765)
    await start_server
    print("Server started on ws://0.0.0.0:18765")

    # 连接到远程WebSocket服务端
    await connect_to_remote()

    # 开始从远程服务端接收消息并转发给客户端
    await forward_from_remote_to_clients()

if __name__ == "__main__":
    asyncio.run(main())